﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Gre_Wp7
{
    public partial class AutoPage : PhoneApplicationPage
    {
        Engine engine = new Engine(true);

        Word wd = new Word();

        int _curPage = 0;

        public AutoPage()
        {
            InitializeComponent();
            _curPage = engine.GetBestPage();

            PageInit(_curPage);
        }

        private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
        {

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            engine.RememberPage(_curPage);
            _curPage = engine.GetBestPage();
            PageInit(_curPage);

        }


        private void PageInit(int page)
        {
            CWord[] cw = wd.GetPageArray(page);
            PageIndex.Text = page.ToString();
            listBox1.Items.Clear();
            int num = 1;
            foreach (CWord c in cw)
            {
                listBox1.Items.Add(string.Format("[{0}] {1}", num + page * 5, c.English));
                listBox1.Items.Add(c.Meaning);
                num++;
            };
        }

        private void PageIndex_MouseEnter(object sender, MouseEventArgs e)
        {
            engine.SaveToFile();
        }

        private void button2_Click_1(object sender, RoutedEventArgs e)
        {
            engine.RememberPage(_curPage);
            _curPage = engine.GetBestPage();
            PageInit(_curPage);
        }
    }
}